import { createStore } from 'vuex'
const state = {
  name:'全局的name属性',
  selectQuestionList:[],
  paperquestionList:[],   // paperquestionList的全局状态
  question: Object,
  paper: Object,
  genaralPaper: Object,
  index: -1,
  selcetKnowledgepointList:[],
  selectedPaperId: -1,
  importQuestionType: "importQuestionsAndPaper",
}
const getters = {
  getName(state){
    return state.name
  },
  getQuestionListValue(state){
    return state.paperquestionList
  }
}
const mutations = {
  setPaper(state, value){
    state.paper = value
  },
  setGenaralPaper(state, value){    
    state.paper = value
  },
  setPaperId(state, value){
    state.selectedPaperId = value
  },
  setQuestion(state, value){    
    state.question = value
  },
  setName(state,name){
    state.name = name
  },
  setIndex(state, index){
    state.index = index
  },
  setSelectQuestionList(state,questionListValue){
    state.selectQuestionList = questionListValue.slice(0)
    console.log("我是全局，收到题目：",state.selectQuestionList)
  },
  // 初始化题目列表或者整体覆盖更新，接收整个题目列表
  setQuestionListValue(state, questionListValue){
    // console.log("全局收到题目列表：", questionListValue)
    state.paperquestionList = questionListValue.slice(0)
  },
  // 设置知识点的id
  setQuestionListKnowledgepoint(state, value){
    state.paperquestionList[value.id].knowledgepoint=value.value_id
    state.paperquestionList[value.id].knowledgepoint_cn=value.value_name
  },
  //设置题目插图
  setQuestionListPicture(state, value){
    if(state.paperquestionList[value.id].pictures==""){
      state.paperquestionList[value.id].pictures=value.pictures
    }else{
      state.paperquestionList[value.id].pictures+="-"+value.pictures
    }       
  },
  setSelcetKnowledgepointList(state, value_list){
    state.selcetKnowledgepointList = value_list
  }
}
const actions = {

}
const modules = {

}
const store = createStore({
  state,
  getters,
  mutations,
  actions,
  modules,
  strict:true
})
export default store